<template>
    <!-- pages/wallet/checkAccount/index.wxml -->
    <!-- pages/wallet/checkAccount/index.wxml -->
    <view>
        <view class="title">请绑定本人银行卡账户</view>
        <!-- 检查是否绑定过厦门银行 -->
        <view class="cardbox">
            <view class="centers box">
                <view>持卡人姓名</view>
                <view><input @input="getinput" class="widthinput" type="text" :value="name" placeholder="输入您的姓名" /></view>
            </view>
            <view class="centers box">
                <view>持卡人身份证</view>
                <view><input @input="getUserno" class="widthinput" type="idcard" :value="userNo" placeholder="输入您的身份证" /></view>
            </view>
        </view>
        <view class="btn" @tap="onCheck">下一步</view>
    </view>
</template>

<script>
// pages/wallet/checkAccount/index.js
import _request from '../../../utils/request.js';
export default {
    data() {
        return {
            name: '',
            userNo: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        //检查是否绑定过厦门银行
        onCheck() {
            const { name, userNo } = this;
            let vm = this;

            if (vm.getRule1()) {
                _request
                    .get('/tfs/checkUserStatus', {
                        userId: uni.getStorageSync('userid'),
                        role: 3,
                        idNo: userNo,
                        custName: name
                    })
                    .then((res) => {
                        // 绑定验证 (data=5未实名，1是已实名)
                        if (res.data.data) {
                            if (res.data.data == 1) {
                                uni.showModal({
                                    title: '温馨提示',
                                    content: '系统已检测到您在其它端已绑定过银行卡, 已自动同步到此账号, 是否要继续添加新的银行卡?',

                                    success(resp) {
                                        if (resp.cancel) {
                                            uni.navigateBack({
                                                delta: 1
                                            });
                                        } else {
                                            uni.navigateTo({
                                                url: '/pages/wallet/addbankcard/index',
                                                success: function (res2) {
                                                    // 通过eventChannel向被打开页面传送数据
                                                    res2.eventChannel.emit('acceptData', {
                                                        checkUserStatus: res.data.data,
                                                        idNo: userNo,
                                                        custName: name
                                                    });
                                                }
                                            });
                                        }
                                    }
                                });
                            } else {
                                uni.navigateTo({
                                    url: '/pages/wallet/addbankcard/index',
                                    success: function (res2) {
                                        // 通过eventChannel向被打开页面传送数据
                                        res2.eventChannel.emit('acceptData', {
                                            checkUserStatus: res.data.data,
                                            idNo: userNo,
                                            custName: name
                                        });
                                    }
                                });
                            }
                        } else {
                            uni.showToast({
                                title: res.data.message,
                                icon: 'none',
                                duration: 1000
                            });
                        }
                    });
            }
        },

        // 持卡人姓名
        getinput(e) {
            let value = e.detail.value;
            this.setData({
                name: value
            });
        },

        // 身份证卡号
        getUserno(e) {
            let value = e.detail.value;
            this.setData({
                userNo: value
            });
        },

        // 验证规则
        getRule1() {
            const { name, userNo } = this;

            if (!name) {
                uni.showToast({
                    title: '请输入姓名',
                    icon: 'none'
                });
                return false;
            } else if (!userNo) {
                uni.showToast({
                    title: '请输入身份证',
                    icon: 'none'
                });
                return false;
            } else {
                return true;
            }
        }
    }
};
</script>
<style>
/* pages/wallet/checkAccount/index.wxss */
.title {
    width: 100%;
    font-size: 24rpx;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ff8722;
    text-align: center;
    margin: 30rpx 0;
}

.cardbox {
    width: 710rpx;
    /* height: 434rpx; */
    background: #ffffff;
    box-shadow: 0px 1px 29px 0px rgba(0, 0, 0, 0.04);
    border-radius: 10px;
    margin: 0 20rpx;
}

.btn {
    width: 670rpx;
    height: 90rpx;
    background: #ff8722;
    border-radius: 45px;
    margin: 170rpx 40rpx 0 40rpx;
    font-size: 36rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #f3f3f3;
    line-height: 90rpx;
    text-align: center;
}

.box {
    height: 86rpx;
    border-bottom: 1px sloid #e8e8e8;
    position: relative;
    line-height: 86rpx;
}

.box > view:nth-child(1) {
    font-size: 28rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #333333;
    width: 220rpx;
    text-align: left;
    padding-left: 20rpx;
    box-sizing: border-box;
}

.widthinput {
    font-size: 28rpx;
    font-family: PingFang SC;
    font-weight: 500;
}
</style>
